using System;
using L=Science.Physics.GeneralPhysics;

namespace Serway.Chapter12
{
	/// <summary>
	/// Example03: Standing on a Horizontal Beam
	/// A uniform horizontal beam with a length 
	/// of 8.00 m and a weight of 200 N is attached to a wall 
	/// by a pin connection. Its far end is supported by 
	/// a cable that makes an angle of 53.0 with the 
	/// beam (Fig.12.10a). If a 600 N person stands 2.00 m 
	/// from the wall, find the tension in the cable as well as 
	/// the magnitude and direction of the force exerted by 
	/// the wall on the beam.
	/// T = 313 N
	/// \theta = 71.1^{\circle}
	/// R = 580 N
	/// </summary>
	public class Example03
	{
		public Example03()
		{
		}
		private string result;
		public string Result
		{
			get{return result;}
		}
		public void Compute()
		{
			L.Force[] f = new L.Force[4];
			L.Position[] r = new L.Position[4];

			f[0] = new L.Force();
			f[0].YVariableQ = true;
			f[0].XVariableQ = true;
			f[1] = new L.Force();
			f[1].Y = -600.0;
			f[2] = new L.Force();
			f[2].Y = -200.0;
			f[3] = new L.Force();
			f[3].YVariableQ = true;
			f[3].XVariableQ = true; 
			
			r[0] = new L.Position();
			r[1] = new L.Position();
			r[1].X = 2.0;
			r[2] = new L.Position();
			r[2].X = 4.0;
			r[3] = new L.Position();
			r[3].X = 8.0;
			
			L.RigidBody board = new L.RigidBody();
			L.RigidBody.ConstraintFunctionToBeZero[] cf
				= new L.RigidBody.ConstraintFunctionToBeZero[1];
			cf[0] = new L.RigidBody.ConstraintFunctionToBeZero(Tension);
			board.Constraint(cf);
			board.SolveStaticEquilibrium(r,f);
			
			result+=Convert.ToString(f[0].N)+"\r\n";
			result+=Convert.ToString(f[3].N)+"\r\n";
			result+=Convert.ToString(Math.Atan(f[0].Y/f[0].X)/Math.PI*180.0)+"\r\n";
		}
		private double Tension(L.Position[] r, L.Force[] f)
		{
			return f[3].X*Math.Sin(53.0*Math.PI/180.0)
				+f[3].Y*Math.Cos(53.0*Math.PI/180.0);
		}
	}
}
